home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DRIVES.SWG / 0064_DOS Files Info.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  3KB  |  98 lines

  1. unit FileInfo;
  2. (* FILEINFO scans DOS' "list of lists" to retrieve valuable file information.
  3.    It does this by calling undocumented MSDOS call 52h.  It should be noted
  4.    that this only works for DOS versions 2.0 and higher.  No error checking
  5.    for this is performed.
  6. *)
  7. interface
  8. uses
  9.   dos;
  10. type
  11.   FileTblPtr     = ^FileTables;
  12.   FileTables     = record
  13.     Next:               FileTblPtr;
  14.     NumFiles:           word;
  15.     NumHandles:         byte;
  16.   end;  { FileTables }
  17.   ListofListsRec = record
  18.     DOSDriveParamBlock: pointer;
  19.     DOSFileTbl:         FileTblPtr;
  20.     ClockDevice:        pointer;
  21.     ConDevice:          pointer;
  22.     MaxBytes:           word;
  23.     DiskBuffer:         pointer;
  24.     SubDirectory:       pointer;
  25.     FCBTable:           pointer;
  26.     FCBsProtected:      word;
  27.     NumBlocks:          byte;
  28.     LastDrive:          byte;
  29.   end;  { ListofLists }
  30.   DOSFilesObj = object
  31.     ListOfLists : ^ListofListsRec;
  32.     constructor Init;
  33.     function    LastDrive   : char;
  34.     function    FilesUsed   : integer;
  35.     function    ConfigFiles : integer;
  36.   end;  { ConfigObj }
  37.  
  38. implementation
  39.  
  40. constructor DOSFilesObj.Init;
  41. var
  42.   regs:   registers;
  43. begin
  44.   regs.ah := $52;
  45.   MsDos(regs);       { call undocumented function 52h                    }
  46.                      { returns pointer to list of lists @Regs.ES,Regs.BX }
  47.   ListofLists := Ptr(regs.ES,regs.BX);
  48. end;  { DOSFilesObj.Init }
  49.  
  50. function DOSFilesObj.LastDrive : char;
  51. begin
  52.   LastDrive   := Char(ListofLists^.LastDrive+64);
  53. end;  { DOSFilesObj.LastDrive }
  54.  
  55. function DOSFilesObj.FilesUsed : integer;
  56. var
  57.   n:   integer;
  58.   p:   FileTblPtr;
  59. begin
  60.   n := 0;
  61.   p := ListOfLists^.DOSFileTbl;
  62.   while ofs(p^)<>$FFFF do
  63.   begin
  64.     inc(n,p^.NumHandles);
  65.     p := p^.Next;
  66.   end;  { while }
  67.   FilesUsed := n;
  68. end;  { DOSFilesObj.FilesUsed }
  69.  
  70. function DOSFilesObj.ConfigFiles : integer;
  71. var
  72.   n:   integer;
  73.   p:   FileTblPtr;
  74. begin
  75.   n := 0;
  76.   p := ListOfLists^.DOSFileTbl;
  77.   while ofs(p^)<>$FFFF do
  78.   begin
  79.     inc(n,p^.NumFiles);
  80.     p := p^.Next;
  81.   end;  { while }
  82.   ConfigFiles := n;
  83. end;  { DOSFilesObj.ConfigFiles }
  84.  
  85. end.  { FileInfo }
  86.  
  87. {--------------     DEMO ------------------ }
  88.  
  89. program filetest;
  90. uses fileinfo;
  91. var
  92.   DOSFiles : DOSFilesObj;
  93. begin
  94.   DOSFiles.Init;
  95.   Writeln('LASTDRIVE=',DOSFiles.LastDrive);
  96.   Writeln('DOS FILES USED=',DOSFiles.FilesUsed);
  97.   Writeln('DOS FILES=',DOSFiles.ConfigFiles);
  98. end.  { FileInfo }